import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _find from "lodash/find";
import _isUndefined from "lodash/isUndefined";
import _isString from "lodash/isString";
import _isObject from "lodash/isObject";
import _isNumber from "lodash/isNumber";
import _isEmpty from "lodash/isEmpty";
import _forEach from "lodash/forEach";
var _excluded = ["id", "createFlag"],
    _excluded2 = ["id"],
    _excluded3 = ["id"];

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _class, _class2;

import React, { PureComponent } from 'react';
import { Col, Form, Icon, Input, InputNumber, Modal, Row, Select, Spin, DatePicker, Tooltip, Tabs } from 'antd';
import { Bind } from 'lodash-decorators';
import moment from 'moment';
import { Button as ButtonPermission } from 'components/Permission';
import Lov from 'components/Lov';
import EditTable from 'components/EditTable';
import Switch from 'components/Switch';
import { encryptPwd, getDateFormat, getEditTableData } from 'utils/utils';
import intl from 'utils/intl';
import notification from 'utils/notification';
import { DEFAULT_DATE_FORMAT } from 'utils/constants';
import RoleModal from "./RoleModal";
import styles from "./index.less?modules";
var Option = Select.Option;
var FormItem = Form.Item;
var TextArea = Input.TextArea;
var TabPane = Tabs.TabPane;

function isJSON(str) {
  var result;

  try {
    result = JSON.parse(str);
  } catch (e) {
    return false;
  }

  return _isObject(result) && !_isString(result);
}

var Drawer = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec9 = Bind(), _dec10 = Bind(), _dec11 = Bind(), _dec12 = Bind(), _dec13 = Bind(), _dec14 = Bind(), _dec15 = Bind(), _dec16 = Bind(), _dec17 = Bind(), _dec18 = Bind(), _dec19 = Bind(), _dec20 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(Drawer, _PureComponent);

  var _super = _createSuper(Drawer);

  function Drawer() {
    var _this;

    _classCallCheck(this, Drawer);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      ownedRoleList: [],
      selectedRowKeys: [],
      selectedRows: [],
      visibleRole: false,
      // dataSource: [], // 客户端表格的信息
      currentClientId: '',
      roleType: 'permission',
      selectedVisitRowKeys: []
    };
    return _this;
  }

  _createClass(Drawer, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.queryOwnedRole();
    } // 查询当前已分配角色

  }, {
    key: "queryOwnedRole",
    value: function queryOwnedRole() {
      var _this2 = this;

      var fields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var _this$props = this.props,
          dispatch = _this$props.dispatch,
          detailStatus = _this$props.detailStatus,
          detailRecord = _this$props.detailRecord,
          fetchDetailData = _this$props.fetchDetailData;

      switch (detailStatus) {
        case 'update':
          fetchDetailData(detailRecord).then(function (res) {
            if (res) {
              dispatch({
                type: 'client/roleCurrent',
                payload: {
                  clientId: res.id,
                  memberType: 'client',
                  page: _isEmpty(fields) ? {} : fields
                }
              }).then(function (detailRes) {
                var form = _this2.props.form;

                if (detailRes) {
                  form.resetFields();

                  _this2.setState({
                    // 对获取到的用户列表进行处理，加入_status属性
                    ownedRoleList: detailRes.content.map(function (r) {
                      return _objectSpread(_objectSpread({}, r), {}, {
                        _status: 'update'
                      });
                    }),
                    currentClientId: res.id
                  });
                }
              });
              dispatch({
                type: 'client/roleVisitCurrent',
                payload: {
                  clientId: res.id,
                  page: _isEmpty(fields) ? {} : fields,
                  organizationId: res.organizationId
                }
              });
            }
          });
          break;

        default:
          break;
      }
    }
  }, {
    key: "handleAfterAddPermissionRole",
    value: function handleAfterAddPermissionRole() {
      var _this3 = this;

      var fields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var dispatch = this.props.dispatch;
      var _this$state = this.state,
          currentClientId = _this$state.currentClientId,
          roleType = _this$state.roleType;

      if (roleType === 'permission') {
        dispatch({
          type: 'client/roleCurrent',
          payload: {
            clientId: currentClientId,
            memberType: 'client',
            page: _isEmpty(fields) ? {} : fields
          }
        }).then(function (detailRes) {
          var form = _this3.props.form;

          if (detailRes) {
            form.resetFields();

            _this3.setState({
              // 对获取到的用户列表进行处理，加入_status属性
              ownedRoleList: detailRes.content.map(function (r) {
                return _objectSpread(_objectSpread({}, r), {}, {
                  _status: 'update'
                });
              })
            });
          }
        });
      } else {
        dispatch({
          type: 'client/roleVisitCurrent',
          payload: {
            clientId: currentClientId,
            page: _isEmpty(fields) ? {} : fields
          }
        });
      }
    }
    /**
     * 模态框确定-保存客户端
     */

  }, {
    key: "onOk",
    value: function onOk() {
      var _this4 = this;

      var _this$props2 = this.props,
          onOk = _this$props2.onOk,
          form = _this$props2.form,
          publicKey = _this$props2.publicKey,
          initData = _this$props2.initData;
      form.validateFields(function (error, fieldsValue) {
        if (!error) {
          // ownedRoleList 获取到的用户列表
          var _this4$state$ownedRol = _this4.state.ownedRoleList,
              ownedRoleList = _this4$state$ownedRol === void 0 ? [] : _this4$state$ownedRol; // validatingDataSource 可编辑的数据

          var validatingDataSource = ownedRoleList.filter(function (r) {
            return r._status === 'create' || r._status === 'update' && r.manageableFlag === 1;
          }); // validateSource 编辑后的数据
          // TODO: 没有编辑的数据不传给后端，这里是把所有可编辑的数据全部都传了

          var validateDataSource = getEditTableData(validatingDataSource, ['_status']);
          var memberRoleList = validateDataSource.filter(function (i) {
            var j = _find(validatingDataSource, function (or) {
              return or.id === i.id;
            });

            return j._status === 'update' && (j.startDateActive !== i.startDateActive || j.endDateActive !== i.endDateActive) || j._status === 'create';
          }).map(function (r) {
            return _objectSpread(_objectSpread({}, r), {}, {
              roleId: r.roleId || r.id,
              // roleId: r.id,
              assignLevel: r.assignLevel,
              assignLevelValue: r.assignLevelValue,
              memberId: initData.id,
              memberType: 'client',
              startDateActive: r.startDateActive && r.startDateActive.format(DEFAULT_DATE_FORMAT),
              endDateActive: r.endDateActive && r.endDateActive.format(DEFAULT_DATE_FORMAT)
            });
          });

          var newValue = _objectSpread({}, fieldsValue);

          if (fieldsValue.secret) {
            newValue.secret = encryptPwd(fieldsValue.secret, publicKey);
          }

          var newClient = _objectSpread(_objectSpread({}, newValue), {}, {
            memberRoleList: memberRoleList.map(function (item) {
              if (item.createFlag) {
                var id = item.id,
                    createFlag = item.createFlag,
                    rest = _objectWithoutProperties(item, _excluded);

                return rest;
              } else {
                var _id = item.id,
                    res = _objectWithoutProperties(item, _excluded2);

                return res;
              }
            }) // : memberRoleList
            // .concat(ownedRoleList.filter(
            //   r => r._status === 'create'
            // )),

          }); // if (validatingDataSource.length === validateDataSource.length) {


          onOk(newClient); // }
        }
      });
    }
    /**
     * 校验客户端名称
     * @param rule
     * @param value
     * @param callback
     */

  }, {
    key: "checkName",
    value: function checkName(rule, value, callback) {
      var _this$props3 = this.props,
          dispatch = _this$props3.dispatch,
          tenantId = _this$props3.tenantId;

      if (value) {
        dispatch({
          type: 'client/checkClient',
          payload: {
            tenantId: tenantId,
            name: value
          }
        }).then(function (res) {
          if (isJSON(res) && JSON.parse(res).failed) {
            callback(JSON.parse(res).message);
          } else {
            callback();
          }
        });
      } else {
        // 为空的话, 必输校验 已经 校验了
        callback();
      }
    }
  }, {
    key: "isJson",
    value: function isJson(string) {
      try {
        if (typeof JSON.parse(string) === 'object') {
          return true;
        }
      } catch (e) {
        return false;
      }
    } // 校验作用域和自动授权域

  }, {
    key: "validateSelect",
    value: function validateSelect(rule, value, callback, name) {
      var length = value && value.length;

      if (length) {
        var reg = new RegExp(/^[A-Za-z]+$/);

        if (!reg.test(value[length - 1]) && name === 'scope') {
          callback(intl.get('ciam.client.view.validate.scope').d("\u4F5C\u7528\u57DF\u53EA\u80FD\u5305\u542B\u82F1\u6587\u5B57\u6BCD"));
          return;
        }

        if (!reg.test(value[length - 1]) && name === 'autoApprove') {
          callback(intl.get('ciam.client.view.validate.autoApprove').d("\u81EA\u52A8\u6388\u6743\u57DF\u53EA\u80FD\u5305\u542B\u82F1\u6587\u5B57\u6BCD"));
          return;
        }

        if (length > 6) {
          callback(intl.get('ciam.client.view.validate.maxLength').d('最多只能输入6个域'));
          return;
        }
      }

      callback();
    } // 初始化 授权类型

  }, {
    key: "getAuthorizedGrantTypes",
    value: function getAuthorizedGrantTypes() {
      var _this$props$initData = this.props.initData,
          initData = _this$props$initData === void 0 ? {} : _this$props$initData;

      var createFlag = _isUndefined(initData.id);

      if (createFlag) {
        return ['password', 'implicit', 'client_credentials', 'authorization_code', 'refresh_token'];
      }

      return initData.authorizedGrantTypes ? initData.authorizedGrantTypes.split(',') : [];
    } // 删除选中的角色

  }, {
    key: "handleRoleRemoveBtnClick",
    value: function handleRoleRemoveBtnClick() {
      var _this$props4 = this.props,
          _this$props4$initData = _this$props4.initData,
          initData = _this$props4$initData === void 0 ? {} : _this$props4$initData,
          dispatch = _this$props4.dispatch,
          paginationRole = _this$props4.paginationRole;
      var _this$state2 = this.state,
          selectedRows = _this$state2.selectedRows,
          selectedRowKeys = _this$state2.selectedRowKeys,
          ownedRoleList = _this$state2.ownedRoleList;
      var that = this;

      if (selectedRows.filter(function (i) {
        return i._status !== 'create';
      }).length === 0) {
        if (selectedRowKeys.length === 0) {
          Modal.error({
            content: intl.get('ciam.client.view.message.chooseRoleFirst').d('请先选择要删除的角色')
          });
          return;
        } else {
          that.setState({
            ownedRoleList: ownedRoleList.filter(function (item) {
              return !selectedRowKeys.includes(item.id);
            })
          });
          return;
        }
      }

      Modal.confirm({
        title: intl.get('cpaas.common.message.confirm.title').d('提示'),
        content: intl.get("ciam.client.view.message.title.content").d('确定删除吗？'),
        onOk: function onOk() {
          var ids = [];
          selectedRows.filter(function (i) {
            return i._status !== 'create';
          }).forEach(function (item) {
            ids.push({
              roleId: item.id,
              memberType: 'client',
              memberId: initData.id
            });
          });
          dispatch({
            type: 'client/deleteRoles',
            payload: {
              memberRoleList: ids
            }
          }).then(function (res) {
            if (res) {
              that.queryOwnedRole(paginationRole);
              that.setState({
                selectedRowKeys: []
              });
              notification.success();
            }
          });
        }
      });
    }
    /**
     * 渲染 分配角色Table
     */

  }, {
    key: "renderRoleTable",
    value: function renderRoleTable() {
      var _this$state3 = this.state,
          _this$state3$ownedRol = _this$state3.ownedRoleList,
          ownedRoleList = _this$state3$ownedRol === void 0 ? [] : _this$state3$ownedRol,
          _this$state3$selected = _this$state3.selectedRowKeys,
          selectedRowKeys = _this$state3$selected === void 0 ? [] : _this$state3$selected;
      var _this$props5 = this.props,
          isSameUser = _this$props5.isSameUser,
          fetchOwnedLoading = _this$props5.fetchOwnedLoading,
          paginationRole = _this$props5.paginationRole;
      var rowSelection = isSameUser ? null : {
        selectedRowKeys: selectedRowKeys,
        onChange: this.handleRoleSelectionChange
      };
      var columns = [{
        title: intl.get('ciam.client.model.client.roleName').d('角色名称'),
        dataIndex: 'name',
        width: 100
      }, {
        title: intl.get('entity.tenant.name').d('租户名称'),
        dataIndex: 'tenantName'
      }, {
        title: intl.get('ciam.subAccount.model.role.startDateActive').d('起始时间'),
        key: 'startDateActive',
        width: 160,
        render: function render(_, record) {
          var $form = record.$form;
          var getFieldDecorator = $form.getFieldDecorator;
          var dateFormat = getDateFormat();
          return /*#__PURE__*/React.createElement(Form.Item, null, getFieldDecorator('startDateActive', {
            initialValue: record.startDateActive ? moment(record.startDateActive, DEFAULT_DATE_FORMAT) : undefined
          })( /*#__PURE__*/React.createElement(DatePicker, {
            format: dateFormat,
            style: {
              width: '100%'
            },
            placeholder: null,
            disabled: record.manageableFlag === 0,
            disabledDate: function disabledDate(currentDate) {
              return $form.getFieldValue('endDateActive') && moment($form.getFieldValue('endDateActive')).isBefore(currentDate, 'day');
            }
          })));
        }
      }, {
        title: intl.get('ciam.subAccount.model.role.endDateActive').d('失效时间'),
        key: 'endDateActive',
        width: 160,
        render: function render(_, record) {
          var $form = record.$form;
          var getFieldDecorator = $form.getFieldDecorator;
          var dateFormat = getDateFormat();
          return /*#__PURE__*/React.createElement(Form.Item, null, getFieldDecorator('endDateActive', {
            initialValue: record.endDateActive ? moment(record.endDateActive, DEFAULT_DATE_FORMAT) : undefined
          })( /*#__PURE__*/React.createElement(DatePicker, {
            format: dateFormat,
            style: {
              width: '100%'
            },
            placeholder: null,
            disabled: record.manageableFlag === 0,
            disabledDate: function disabledDate(currentDate) {
              return $form.getFieldValue('startDateActive') && moment($form.getFieldValue('startDateActive')).isAfter(currentDate, 'day');
            }
          })));
        }
      }];
      return /*#__PURE__*/React.createElement(EditTable, {
        rowKey: "id",
        bordered: true,
        onChange: this.handleAfterAddPermissionRole,
        loading: fetchOwnedLoading,
        rowSelection: rowSelection,
        dataSource: ownedRoleList,
        columns: columns,
        pagination: paginationRole
      });
    }
    /**
     * 渲染 分配角色Table
     */

  }, {
    key: "renderVisitRoleTable",
    value: function renderVisitRoleTable() {
      var _this$state$selectedV = this.state.selectedVisitRowKeys,
          selectedVisitRowKeys = _this$state$selectedV === void 0 ? [] : _this$state$selectedV;
      var _this$props6 = this.props,
          isSameUser = _this$props6.isSameUser,
          fetchOwnedLoading = _this$props6.fetchOwnedLoading,
          visitRoleList = _this$props6.visitRoleList,
          visitRolePagination = _this$props6.visitRolePagination;
      var rowSelection = isSameUser ? null : {
        selectedVisitRowKeys: selectedVisitRowKeys,
        onChange: this.handleVisitRoleSelectionChange
      };
      var columns = [{
        title: intl.get('ciam.client.model.client.roleName').d('角色名称'),
        dataIndex: 'name',
        width: 300
      }, {
        title: intl.get('entity.tenant.name').d('租户名称'),
        dataIndex: 'tenantName'
      }];
      return /*#__PURE__*/React.createElement(EditTable, {
        rowKey: "id",
        bordered: true,
        onChange: this.handleAfterAddPermissionRole,
        loading: fetchOwnedLoading,
        rowSelection: rowSelection,
        dataSource: visitRoleList,
        columns: columns,
        pagination: visitRolePagination
      });
    }
    /**
     * 打开新增角色 选择模态框
     */

  }, {
    key: "handleRoleAddBtnClick",
    value: function handleRoleAddBtnClick() {
      var _this$state$ownedRole = this.state.ownedRoleList,
          ownedRoleList = _this$state$ownedRole === void 0 ? [] : _this$state$ownedRole;
      var roleModalProps = {
        excludeRoleIds: [],
        excludeUserIds: []
      };
      ownedRoleList.forEach(function (r) {
        roleModalProps.excludeRoleIds.push(r.id);
      });
      this.setState({
        visibleRole: true,
        roleModalProps: roleModalProps
      });
    }
    /**
     * 打开新增角色 选择模态框
     */

  }, {
    key: "handleVisitRoleAddBtnClick",
    value: function handleVisitRoleAddBtnClick() {
      // const { ownedRoleList = [] } = this.state;
      var visitRoleList = this.props.visitRoleList;
      var roleModalProps = {
        excludeVisitRoleIds: [],
        excludeUserIds: []
      };
      visitRoleList.forEach(function (r) {
        roleModalProps.excludeVisitRoleIds.push(r.id);
      });
      this.setState({
        visibleRole: true,
        roleModalProps: roleModalProps
      });
    } // 删除选中的角色

  }, {
    key: "handleVisitRoleRemoveBtnClick",
    value: function handleVisitRoleRemoveBtnClick() {
      var _this$props7 = this.props,
          _this$props7$initData = _this$props7.initData,
          initData = _this$props7$initData === void 0 ? {} : _this$props7$initData,
          dispatch = _this$props7.dispatch,
          paginationRole = _this$props7.paginationRole;
      var _this$state4 = this.state,
          roleType = _this$state4.roleType,
          selectedVisitRowKeys = _this$state4.selectedVisitRowKeys;
      var that = this;

      if (selectedVisitRowKeys.length === 0) {
        Modal.error({
          content: intl.get('ciam.client.view.message.chooseRoleFirst').d('请先选择要删除的角色')
        });
        return;
      }

      Modal.confirm({
        title: intl.get('cpaas.common.message.confirm.title').d('提示'),
        content: intl.get("ciam.client.view.message.title.content").d('确定删除吗？'),
        onOk: function onOk() {
          var ids = [];
          selectedVisitRowKeys.forEach(function (item) {
            ids.push({
              roleId: item,
              memberId: initData.id
            });
          });
          dispatch({
            type: roleType === 'permission' ? 'client/deleteRoles' : 'client/deleteVisitRoles',
            payload: {
              clientId: initData.id,
              memberRoleList: ids.map(function (item) {
                var id = item.id,
                    rest = _objectWithoutProperties(item, _excluded3);

                return rest;
              })
            }
          }).then(function (res) {
            if (res) {
              that.queryOwnedRole(paginationRole);
              that.setState({
                selectedRowKeys: []
              });
              notification.success();
            }
          });
        }
      });
    }
  }, {
    key: "fetchRoles",
    value: function fetchRoles(fields) {
      var fetchAllRoles = this.props.fetchAllRoles;
      return fetchAllRoles(fields);
    }
    /**
     * 新增角色模态框确认按钮点击
     */

  }, {
    key: "handleRoleAddSaveBtnClick",
    value: function handleRoleAddSaveBtnClick(roles) {
      var _this5 = this;

      var _this$props8 = this.props,
          tenantId = _this$props8.tenantId,
          dispatch = _this$props8.dispatch,
          paginationRole = _this$props8.paginationRole,
          initData = _this$props8.initData;
      var roleType = this.state.roleType;
      var memberRoleList = [];

      _forEach(roles, function (record) {
        var newRecord = {
          id: record.id,
          roleId: record.id,
          assignLevel: 'organization',
          memberType: 'client',
          memberId: initData.id,
          sourceId: tenantId,
          sourceType: record.level,
          assignLevelValue: record.tenantId,
          name: record.name,
          assignLevelValueMeaning: record.assignLevelValueMeaning,
          tenantName: record.tenantName,
          createFlag: true
        };

        if (roleType === 'visit') {
          delete newRecord.memberType;
        } // newRecord.assignLevelValue = record.assignLevelValue || tenantId;


        if (!_isEmpty(newRecord.assignLevel) && _isNumber(newRecord.assignLevelValue)) {
          memberRoleList.push(newRecord);
        }
      });

      var payload = roleType === 'permission' ? [].concat(memberRoleList) : {
        memberRoleList: memberRoleList,
        clientId: initData.id // organizationId: initData.organizationId,

      };
      return dispatch({
        type: roleType === 'permission' ? 'client/saveRoleSet' : 'client/saveVisitRoleSet',
        payload: payload
      }).then(function (res) {
        if (res) {
          if (roleType === 'permission') {
            _this5.setState({
              visibleRole: false
            }, function () {
              _this5.setState({
                ownedRoleList: _this5.state.ownedRoleList.concat(res)
              }); // this.handleAfterAddPermissionRole(paginationRole);

            });
          } else {
            _this5.setState({
              visibleRole: false
            }, function () {
              notification.success();

              _this5.queryOwnedRole(paginationRole); // this.handleAfterAddPermissionRole(paginationRole);

            });
          }
        }
      });
    }
    /**
     * 新增角色模态框取消按钮点击
     */

  }, {
    key: "handleRoleAddCancelBtnClick",
    value: function handleRoleAddCancelBtnClick() {
      this.setState({
        visibleRole: false
      });
    }
    /**
     * @param {String[]} selectedRowKeys 选中的rowKey
     */

  }, {
    key: "handleRoleSelectionChange",
    value: function handleRoleSelectionChange(selectedRowKeys, selectedRows) {
      this.setState({
        selectedRowKeys: selectedRowKeys,
        selectedRows: selectedRows
      });
    }
  }, {
    key: "handleVisitRoleSelectionChange",
    value: function handleVisitRoleSelectionChange(selectedVisitRowKeys) {
      this.setState({
        selectedVisitRowKeys: selectedVisitRowKeys
      });
    }
  }, {
    key: "handleChangeRoleType",
    value: function handleChangeRoleType(type) {
      this.setState({
        roleType: type
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this6 = this;

      var _this$props9 = this.props,
          path = _this$props9.path,
          form = _this$props9.form,
          _this$props9$initData = _this$props9.initData,
          initData = _this$props9$initData === void 0 ? {} : _this$props9$initData,
          _this$props9$typeList = _this$props9.typeList,
          typeList = _this$props9$typeList === void 0 ? [] : _this$props9$typeList,
          title = _this$props9.title,
          visible = _this$props9.visible,
          onCancel = _this$props9.onCancel,
          loading = _this$props9.loading,
          loadingDistributeUsers = _this$props9.loadingDistributeUsers,
          saveRoleLoading = _this$props9.saveRoleLoading,
          detailStatus = _this$props9.detailStatus,
          _this$props9$fetchLoa = _this$props9.fetchLoading,
          fetchLoading = _this$props9$fetchLoa === void 0 ? false : _this$props9$fetchLoa,
          isTenantRoleLevel = _this$props9.isTenantRoleLevel;
      var getFieldDecorator = form.getFieldDecorator;
      var _this$state5 = this.state,
          selectedRowKeys = _this$state5.selectedRowKeys,
          visibleRole = _this$state5.visibleRole,
          _this$state5$roleModa = _this$state5.roleModalProps,
          roleModalProps = _this$state5$roleModa === void 0 ? {} : _this$state5$roleModa,
          roleType = _this$state5.roleType,
          selectedVisitRowKeys = _this$state5.selectedVisitRowKeys;
      var updateFlag = detailStatus === 'update';
      var formLayout = {
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        }
      };
      return /*#__PURE__*/React.createElement(Modal, {
        width: 1000,
        title: title,
        visible: visible,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        onOk: this.onOk,
        onCancel: onCancel,
        confirmLoading: loading,
        destroyOnClose: true
      }, /*#__PURE__*/React.createElement(Spin, {
        spinning: fetchLoading
      }, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, {
        gutter: 24,
        type: "flex"
      }, !isTenantRoleLevel && /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('entity.tenant.tag').d('租户')
      }), getFieldDecorator('organizationId', {
        initialValue: initData.organizationId,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('entity.tenant.tag').d('租户')
          })
        }]
      })( /*#__PURE__*/React.createElement(Lov, {
        code: "CPFM.TENANT",
        textField: "tenantName",
        disabled: updateFlag,
        textValue: initData.tenantName
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.name').d('名称')
      }), getFieldDecorator('name', {
        initialValue: initData.name,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.client.model.client.name').d('名称')
          })
        }, {
          pattern: /^[0-9a-zA-Z-]{0,32}$/,
          message: intl.get('ciam.client.model.client.namePattern').d('客户端名称只能由1-32位的数字或字母或中划线组成')
        }, {
          validator: !updateFlag && this.checkName
        }],
        validateTrigger: 'onBlur'
      })( /*#__PURE__*/React.createElement(Input, {
        disabled: updateFlag
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.secret').d('密钥')
      }), getFieldDecorator('secret', {
        initialValue: initData.secret,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.client.model.client.secret').d('密钥')
          })
        }, {
          max: 110,
          message: intl.get('cpaas.common.validation.max', {
            max: 110
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        type: "password"
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.authorizedGrantTypes').d('授权类型')
      }), getFieldDecorator('authorizedGrantTypes', {
        // initialValue: initData.authorizedGrantTypes,
        initialValue: this.getAuthorizedGrantTypes(),
        rules: [{
          type: 'array',
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.client.model.client.authorizedGrantTypes').d('授权类型')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, {
        mode: "multiple",
        style: {
          width: '100%'
        }
      }, typeList.map(function (item) {
        return /*#__PURE__*/React.createElement(Option, {
          label: item.meaning,
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.accessTokenValidity').d('访问授权超时(秒)')
      }), getFieldDecorator('accessTokenValidity', {
        // eslint-disable-next-line no-nested-ternary
        initialValue: !updateFlag ? 3600 : initData.accessTokenValidity ? parseInt(initData.accessTokenValidity, 10) : undefined
      })( /*#__PURE__*/React.createElement(InputNumber, {
        style: {
          width: '100%'
        },
        min: 60
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.refreshTokenValidity').d('授权超时(秒)')
      }), getFieldDecorator('refreshTokenValidity', {
        // eslint-disable-next-line no-nested-ternary
        initialValue: !updateFlag ? 3600 : initData.refreshTokenValidity ? parseInt(initData.refreshTokenValidity, 10) : undefined
      })( /*#__PURE__*/React.createElement(InputNumber, {
        style: {
          width: '100%'
        },
        min: 60
      })))), updateFlag && /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        // label={intl.get('ciam.client.model.client.scope').d('作用域')}
        label: /*#__PURE__*/React.createElement("span", null, intl.get('ciam.client.model.client.scope').d('作用域'), "\xA0", /*#__PURE__*/React.createElement(Tooltip, {
          title: intl.get('ciam.client.view.message.scope.help.msg').d('作用域为申请的授权范围。您最多可输入6个域')
        }, /*#__PURE__*/React.createElement(Icon, {
          type: "question-circle-o"
        })))
      }), getFieldDecorator('scope', {
        initialValue: initData.scope ? initData.scope.split(',') : [],
        rules: [{
          validator: function validator(rule, value, callback) {
            return _this6.validateSelect(rule, value, callback, 'scope');
          }
        }],
        validateTrigger: 'onChange'
      })( /*#__PURE__*/React.createElement(Select, {
        mode: "tags",
        style: {
          width: '100%'
        }
      })))), updateFlag && /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        // label={intl.get('ciam.client.model.client.autoApprove').d('自动授权域')}
        label: /*#__PURE__*/React.createElement("span", null, intl.get('ciam.client.model.client.autoApprove').d('自动授权域'), "\xA0", /*#__PURE__*/React.createElement(Tooltip, {
          title: intl.get('ciam.client.view.message.autoApprove.help.msg').d('自动授权域为oauth认证后，系统自动授权而非用户手动添加的作用域。您最多可输入6个域')
        }, /*#__PURE__*/React.createElement(Icon, {
          type: "question-circle-o"
        })))
      }), getFieldDecorator('autoApprove', {
        initialValue: initData.autoApprove ? initData.autoApprove.split(',') : [],
        rules: [{
          validator: function validator(rule, value, callback) {
            return _this6.validateSelect(rule, value, callback, 'autoApprove');
          }
        }],
        validateTrigger: 'onChange'
      })( /*#__PURE__*/React.createElement(Select, {
        mode: "tags",
        style: {
          width: '100%'
        }
      })))), updateFlag && /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.webServerRedirectUri').d('重定向地址')
      }), getFieldDecorator('webServerRedirectUri', {
        initialValue: initData.webServerRedirectUri
      })( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.timeZone').d('时区')
      }), getFieldDecorator('timeZone', {
        initialValue: initData.timeZone,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.client.model.client.timeZone').d('时区')
          })
        }]
      })( /*#__PURE__*/React.createElement(Lov, {
        code: "CIAM.TIME_ZONE",
        textValue: initData.timeZoneMeaning,
        textField: "timeZoneMeaning",
        allowClear: false
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('cpaas.common.button.enable').d('启用')
      }), getFieldDecorator('enabledFlag', {
        initialValue: updateFlag ? initData.enabledFlag : 1
      })( /*#__PURE__*/React.createElement(Switch, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.pwdReplayFlag').d('密码防重放')
      }), getFieldDecorator('pwdReplayFlag', {
        initialValue: updateFlag ? initData.pwdReplayFlag : 1
      })( /*#__PURE__*/React.createElement(Switch, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.apiEncryptFlag').d('接口加密')
      }), getFieldDecorator('apiEncryptFlag', {
        initialValue: updateFlag ? initData.apiEncryptFlag : 1
      })( /*#__PURE__*/React.createElement(Switch, null)))), updateFlag && /*#__PURE__*/React.createElement(Col, {
        span: 12
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('ciam.client.model.client.additionalInformation').d('附加信息')
      }), getFieldDecorator('additionalInformation', {
        initialValue: initData.additionalInformation,
        rules: [{
          validator: function validator(rule, value, callback) {
            if (!value || _this6.isJson(value)) {
              callback();
            } else {
              callback(intl.get('ciam.client.view.validate.additionalInformation').d('请输入正确的json字符串'));
            }
          }
        }],
        validateTrigger: 'onBlur'
      })( /*#__PURE__*/React.createElement(TextArea, {
        rows: 5
      }))))), updateFlag && /*#__PURE__*/React.createElement(Tabs, {
        tabBarGutter: 10,
        defaultActiveKey: "permission",
        animated: true,
        onChange: this.handleChangeRoleType
      }, /*#__PURE__*/React.createElement(TabPane, {
        tab: /*#__PURE__*/React.createElement(React.Fragment, null, intl.get('ciam.client.view.title.tab.visitRole').d('可访问角色'), "\xA0", /*#__PURE__*/React.createElement(Tooltip, {
          title: intl.get('ciam.client.view.message.title.permissionRole').d('该客户端可使用以下角色的权限')
        }, /*#__PURE__*/React.createElement(Icon, {
          type: "question-circle-o"
        }))),
        key: "permission"
      }, updateFlag && /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(FormItem, {
        style: {
          textAlign: 'right'
        }
      }, /*#__PURE__*/React.createElement(Col, {
        span: 23
      }, /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.deleteRole"),
          type: 'button',
          meaning: '客户端-删除角色'
        }],
        style: {
          marginRight: 8
        },
        onClick: this.handleRoleRemoveBtnClick,
        disabled: selectedRowKeys.length === 0
      }, intl.get('cpaas.common.button.delete').d('删除')), /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.createRole"),
          type: 'button',
          meaning: '客户端-新建角色'
        }],
        type: "primary",
        onClick: function onClick() {
          return _this6.handleRoleAddBtnClick();
        }
      }, intl.get('cpaas.common.button.create').d('新建')))))), updateFlag && /*#__PURE__*/React.createElement(Row, {
        type: "flex"
      }, /*#__PURE__*/React.createElement(Col, {
        span: 24,
        className: styles['rule-table']
      }, this.renderRoleTable()))), /*#__PURE__*/React.createElement(TabPane, {
        tab: /*#__PURE__*/React.createElement(React.Fragment, null, intl.get('ciam.client.view.title.tab.perRole').d('授权角色'), "\xA0", /*#__PURE__*/React.createElement(Tooltip, {
          title: intl.get('ciam.client.view.message.title.visitRole').d('拥有以下任意角色的用户可访问该客户端')
        }, /*#__PURE__*/React.createElement(Icon, {
          type: "question-circle-o"
        }))),
        key: "visit"
      }, updateFlag && /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(FormItem, {
        style: {
          textAlign: 'right'
        }
      }, /*#__PURE__*/React.createElement(Col, {
        span: 23
      }, /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.deleteRole"),
          type: 'button',
          meaning: '客户端-删除角色'
        }],
        style: {
          marginRight: 8
        },
        onClick: this.handleVisitRoleRemoveBtnClick,
        disabled: selectedVisitRowKeys.length === 0
      }, intl.get('cpaas.common.button.delete').d('删除')), /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.createRole"),
          type: 'button',
          meaning: '客户端-新建角色'
        }],
        type: "primary",
        onClick: function onClick() {
          return _this6.handleVisitRoleAddBtnClick();
        }
      }, intl.get('cpaas.common.button.create').d('新建')))))), updateFlag && /*#__PURE__*/React.createElement(Row, {
        type: "flex"
      }, /*#__PURE__*/React.createElement(Col, {
        span: 24,
        className: styles['rule-table']
      }, this.renderVisitRoleTable()))))), !!visibleRole && /*#__PURE__*/React.createElement(RoleModal, Object.assign({}, roleModalProps, {
        visible: visibleRole,
        fetchLoading: loadingDistributeUsers,
        saveLoading: saveRoleLoading,
        fetchRoles: this.fetchRoles,
        onSave: this.handleRoleAddSaveBtnClick,
        onCancel: this.handleRoleAddCancelBtnClick,
        roleType: roleType
      }))));
    }
  }]);

  return Drawer;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "queryOwnedRole", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "queryOwnedRole"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleAfterAddPermissionRole", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleAfterAddPermissionRole"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onOk", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "onOk"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "checkName", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "checkName"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "isJson", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "isJson"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "validateSelect", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "validateSelect"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getAuthorizedGrantTypes", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "getAuthorizedGrantTypes"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRoleRemoveBtnClick", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRoleRemoveBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "renderRoleTable", [_dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "renderRoleTable"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "renderVisitRoleTable", [_dec11], Object.getOwnPropertyDescriptor(_class2.prototype, "renderVisitRoleTable"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRoleAddBtnClick", [_dec12], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRoleAddBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleVisitRoleAddBtnClick", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "handleVisitRoleAddBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleVisitRoleRemoveBtnClick", [_dec14], Object.getOwnPropertyDescriptor(_class2.prototype, "handleVisitRoleRemoveBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchRoles", [_dec15], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchRoles"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRoleAddSaveBtnClick", [_dec16], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRoleAddSaveBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRoleAddCancelBtnClick", [_dec17], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRoleAddCancelBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRoleSelectionChange", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRoleSelectionChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleVisitRoleSelectionChange", [_dec19], Object.getOwnPropertyDescriptor(_class2.prototype, "handleVisitRoleSelectionChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleChangeRoleType", [_dec20], Object.getOwnPropertyDescriptor(_class2.prototype, "handleChangeRoleType"), _class2.prototype)), _class2)) || _class);
export { Drawer as default };